package com.huawei.M01.iterator;

public class Reverse {
    public String reverseWords(String s) {
        String[] strings = s.trim().split(" ");
        StringBuilder sb = new StringBuilder();
        for (int i = strings.length - 1; i >= 0; i--) {
            if ("".equals(strings[i])){
                continue;
            }
            sb.append(strings[i].trim()).append(" ");
        }
        return sb.toString().trim();
    }

    public static void main(String[] args) {
        Reverse reverse = new Reverse();
        System.out.println(reverse.reverseWords("a good   example"));
    }
}
